package com.zhiyou.listener;

import java.io.IOException;


import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhiyou.utils.SmsUtil;


@Component
public class QueueListener implements MessageListener {
		
	//创建解析message的对象
	private static final ObjectMapper MAPPER = new ObjectMapper();
	
	@Autowired
	SmsUtil sms; 
	
	public void onMessage(Message message) {
		
	try {
		JsonNode json = MAPPER.readTree(message.getBody());
		String mobile = json.get("mobile").asText();
		String code = json.get("code").asText();
		System.out.println("从消息队列中获取用户的手机号："+mobile);	
		System.out.println("从消息队列中获取用户的验证码："+code);	
		sms.sendSms("18295696428", "SMS_205401859", "飞象校园安全管理系统", "{\"code\":"+code+"}");
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	}

}
